<?php
namespace Org\Util;
class Smsbao{
    /**
     * 短信宝 短信接口
    */
    protected $testtxt='【515学车网】您的验证码为1234，在30分钟内有效，若非本人操作请忽略此消息';
    protected $mobile;
    protected $text;//短信内容
    protected $company="【515学车网】";
    protected $ch;
    protected $username='zhonghengkj';//短信账号用户名 密码
    protected $password='339522491zm';

    public function __construct($mobile,$text) {
        $this->ch=curl_init();
        /* 设置验证方式 */
        curl_setopt($this->ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
        /* 设置返回结果为流 */
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
        /* 设置超时时间*/
        curl_setopt($this->ch, CURLOPT_TIMEOUT, 10);
        /* 设置通信方式 */
        curl_setopt($this->ch, CURLOPT_POST, 1);
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
        $this->text=$text;
        $this->mobile=$mobile;
        $this->password=md5($this->password);
    }
    // 发送短信
    public function send(){
        $reqdata=http_build_query(array(
            'u'=>$this->username,
            'p'=>$this->password,
            'm'=>$this->mobile,
            'c'=>$this->company.$this->text
        ));
        curl_setopt ($this->ch, CURLOPT_URL, 'http://api.smsbao.com/sms');
        curl_setopt($this->ch, CURLOPT_POSTFIELDS, $reqdata);
        $ret=curl_exec($this->ch);
        curl_close($this->ch);
//        $ret=json_decode($ret,1);
//         dump($ret);die;
        return $ret;
    }
}